<?php

$view = '
		<form method="get" action="<?php echo base_url() . $this->uri->uri_string() ?>" class="side-form constrained ajax-form">
			<fieldset>
				<legend>Filter</legend>';
		
for($counter=1; $field_total >= $counter; $counter++)
{
	$maxlength = NULL;
	if (set_value("view_field_label$counter") == NULL){
		continue;
	}

	$field_label = set_value("view_field_label$counter");
	$field_name = $module_name_lower . '_' . set_value("view_field_name$counter");
	$field_type = set_value("view_field_type$counter");
	
	// DIV container for the side form
	$view .= '
		
			<div>';
	
	// Form Label
	$view .= '
				<label for="'.$field_name.'">' . $field_label . '</label>
				<div class="input">
				';
	
	
	// Create form input depends on field type
	switch($field_type)
	{

	// SELECT box
	case('select'):
	
		$select_options = array('' => 'ALL');
		if (set_value("db_field_length_value$counter") != NULL){
			$select_options = explode(',', set_value("db_field_length_value$counter"));
		}
		
		$view .= '
				<?php $options = array(
					\'\' => lang(\''.$module_name_lower.'_all\'),';
		foreach( $select_options as $key => $option){
			$view .= '
				'.strip_slashes($option).' => '.strip_slashes($option).',';
		}
		$view .= '
				); ?>
				<?php echo form_dropdown(\''.$field_name.'\', $options, $this->input->get(\''.$field_name.'\'))?>
			'.$form_input_delimiters[1];
		
		break;
    
	// RADIO button
	case('radio'):
	
		$radio_options = array('' => 'ALL');
		if (set_value("db_field_length_value$counter") != NULL){
			$radio_options = explode(',', set_value("db_field_length_value$counter"));
		}
		
		$view .= '
				<input id="'.$field_name.'" name="'.$field_name.'" type="radio" class="" value="" <?php echo set_radio(\''.$field_name.'\', \'\'); ?> /> <?php echo lang(\''.$module_name_lower.'_all\') ?>';
		foreach( $radio_options as $key => $option){
			$view .= '
				<input id="'.$field_name.'" name="'.$field_name.'" type="radio" class="" value="'.strip_quotes($option).'" <?php echo set_radio(\''.$field_name.'\', \''.strip_quotes($option).'\'); ?> /> '. strip_quotes($option);
		}
		$view .= '
			' . $form_input_delimiters[1];
		
		break;
	
	// CHECKBOX
	case('checkbox'):

		$select_options = array('' => 'ALL');
		if (set_value("db_field_length_value$counter") != NULL){
			$select_options = explode(',', set_value("db_field_length_value$counter"));
		}
		
		$view .= '
				<?php $options = array(
					\'\' => lang(\''.$module_name_lower.'_all\'),
					1 => lang(\''.$module_name_lower.'_yes\'),
					0 => lang(\''.$module_name_lower.'_no\'),';
		$view .= '
				); ?>
				<?php echo form_dropdown(\''.$field_name.'\', $options, $this->input->get(\''.$field_name.'\'))?>
		'.$form_input_delimiters[1];
		
		break;
	
	// TEXTAREA, INPUT, dan PASSWORD
	case('textarea'):
	case('input'):
	case('password'):
	default: // input.. added bit of error detection setting select as default
						
		if ($field_type == 'input' || $field_type == 'textarea')
		{
			$type = 'text';
		}
		else
		{
			$type = 'password';
		}
		if (set_value("db_field_length_value$counter") != NULL)
		{
			$maxlength = 'maxlength="'.set_value("db_field_length_value$counter").'"';
		}
		$db_field_type = set_value("db_field_type$counter");
		if ($db_field_type != NULL)
		{
			if ($db_field_type == 'DATE')
			{
				$view .= '
				<script>head.ready(function(){$(\'#start_'.$field_name.'\').datepicker({ dateFormat: \'yy-mm-dd\'});});</script>
				<script>head.ready(function(){$(\'#end_'.$field_name.'\').datepicker({ dateFormat: \'yy-mm-dd\'});});</script>';
			}
			elseif ($db_field_type == 'DATETIME')
			{
				$view .= '
				<script>head.ready(function(){$(\'#start_'.$field_name.'\').datetimepicker({ dateFormat: \'yy-mm-dd\', timeFormat: \'hh:mm:ss\'});});</script>
				<script>head.ready(function(){$(\'#end_'.$field_name.'\').datetimepicker({ dateFormat: \'yy-mm-dd\', timeFormat: \'hh:mm:ss\'});});</script>';
			}
		}
		
		if($db_field_type == 'DATE' || $db_field_type == 'DATETIME'){
			$view .= <<<EOT
				<input id="start_{$field_name}" type="{$type}" name="start_{$field_name}" {$maxlength} value="<?php echo \$this->input->get('start_{$field_name}'); ?>"  />
			{$form_input_delimiters[1]}
				
			<div>
				<input id="end_{$field_name}" type="{$type}" name="end_{$field_name}" {$maxlength} value="<?php echo \$this->input->get('end_{$field_name}'); ?>"  />
			{$form_input_delimiters[1]}
EOT;
		}else{

			$view .= <<<EOT

				<input id="{$field_name}" type="{$type}" name="{$field_name}" {$maxlength} value="<?php echo \$this->input->get('{$field_name}'); ?>"  />
			{$form_input_delimiters[1]}
EOT;
		}

		break;

	} // end switch
	
	$view .= '
			</div>';
}

// SUBMIT
$view .= '
		</fieldset>
		<div class="form-actions">
			<input type="submit" name="show" value="<?php echo lang(\''.$module_name_lower.'_show\') ?>" />
			<input type="submit" name="download" value="<?php echo lang(\''.$module_name_lower.'_download\') ?>" />
		</div>
		<?php echo form_close(); ?>';
		
echo $view;